package com.pubinfo.passbook.common.model.ruler;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.pubinfo.passbook.common.entity.TPassbook;
import com.pubinfo.passbook.common.entity.TSourceArtificial;
import com.pubinfo.passbook.common.model.dto.witeoff.Artificial;
import lombok.Data;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.beans.factory.annotation.Autowired;

import java.math.RoundingMode;
import java.util.List;

@Data
public class ReimbursementExcel
{
    @ExcelProperty("票据id")
    @ColumnWidth(40)
    private String invoiceId;
    @ExcelProperty("票据代码")
    @ColumnWidth(20)
    private String invoiceCode;
    @ExcelProperty("票据号码")
    @ColumnWidth(20)
    private String invoiceNumber;
    @ExcelProperty("金额合计")
    @ColumnWidth(20)
    private String totalAmount;
    @ExcelProperty("医疗统筹基金支付")
    @ColumnWidth(20)
    private String fundPayAmount;
    @ExcelProperty("个人账户-本年支付")
    @ColumnWidth(20)
    private String currPayment;
    @ExcelProperty("个人自费")
    @ColumnWidth(20)
    private String selfpaymentCost;
    @ExcelProperty("个人自理")
    @ColumnWidth(20)
    private String selfpaymentCare;
    @ExcelProperty("个人自付")
    @ColumnWidth(20)
    private String selfpaymentAmount;
    @ExcelProperty("报销金额")
    private String reimbursableSum;

    public ReimbursementExcel() {
    }

    public ReimbursementExcel(TPassbook tPassbook)
    {
        this.invoiceCode=tPassbook.getEinvoiceCode();
        this.invoiceId=tPassbook.getEInvoiceId();
        this.invoiceNumber=tPassbook.getEinvoiceNumber();
        this.reimbursableSum=tPassbook.getReimbursableSum().setScale(2, RoundingMode.HALF_UP).toString();
        String xml = tPassbook.getEinvoiceXml();
        Document document = null;
        try {
            document = DocumentHelper.parseText(xml);
        } catch (DocumentException e) {
        }
        Element root = document.getRootElement();
        PayInformation payInformation=new PayInformation(root);
        this.totalAmount=payInformation.getTotalAmount().setScale(2, RoundingMode.HALF_UP).toString();
        this.fundPayAmount=payInformation.getFundPayAmount().setScale(2, RoundingMode.HALF_UP).toString();
        this.currPayment=payInformation.getIndividualAccountCurrPayment().setScale(2, RoundingMode.HALF_UP).toString();
        this.selfpaymentCost=payInformation.getSelfpaymentCost().setScale(2, RoundingMode.HALF_UP).toString();
        this.selfpaymentCare=payInformation.getSelfpaymentCare().setScale(2, RoundingMode.HALF_UP).toString();
        this.selfpaymentAmount=payInformation.getSelfpaymentAmount().setScale(2, RoundingMode.HALF_UP).toString();

    }
    public ReimbursementExcel(TSourceArtificial artificial)
    {
        this.invoiceId="手工录入";
        this.reimbursableSum=artificial.getApprovedAmount().setScale(2, RoundingMode.HALF_UP).toString();
    }
}
